package com.main.toyexchange;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;

import com.bjtu.toyexchange.R;

/*
 * 主页面菜单的activity
 */

public class MenuActivity extends TabActivity implements OnCheckedChangeListener{
	private String username, password;
	private TabHost mHost;
	private RadioGroup radioderGroup;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);
        
        //接受到用户名、密码
        Intent intent = this.getIntent();
		username = intent.getStringExtra("username");
        password = intent.getStringExtra("password");
        mHost = this.getTabHost();
        
        //将用户名传递到主页
        Intent tab1 = new Intent(MenuActivity.this, IndexActivity.class);
        Bundle bun1 = new Bundle();
        bun1.putString("username",username);
        tab1.putExtras(bun1);
        mHost.addTab(mHost.newTabSpec("ONE").setIndicator("ONE")
        		.setContent(tab1)); 

        
        //将用户名传递到发布页面
        Intent tab2 = new Intent(MenuActivity.this, FabuActivity.class);
        Bundle bun2 = new Bundle();
        bun2.putString("username",username);
        tab2.putExtras(bun2);
        mHost.addTab(mHost.newTabSpec("TWO").setIndicator("TWO")
        		.setContent(tab2));
        
        //将用户名传递到消息页面
        Intent tab3 = new Intent(MenuActivity.this, XiaoxiActivity.class);
        Bundle bun3 = new Bundle();
        bun3.putString("username",username);
        tab3.putExtras(bun3);
        mHost.addTab(mHost.newTabSpec("THREE").setIndicator("THREE")
        		.setContent(tab3));
        
        //将用户名传递到个人主页
        Intent tab4 = new Intent(MenuActivity.this, GerenActivity.class);
        Bundle bun4 = new Bundle();
        bun4.putString("username",username);
        bun4.putString("password", password);
        tab4.putExtras(bun4);
        mHost.addTab(mHost.newTabSpec("FOUR").setIndicator("FOUR")
        		.setContent(tab4));
        
        radioderGroup = (RadioGroup) findViewById(R.id.menu_radio);
		radioderGroup.setOnCheckedChangeListener(this);
    }
	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		switch(checkedId) {
		case R.id.radio_zhuye:
			mHost.setCurrentTabByTag("ONE");
			break;
		case R.id.radio_fabu:
			mHost.setCurrentTabByTag("TWO");
			break;
		case R.id.radio_xiaoxi:
			mHost.setCurrentTabByTag("THREE");
			break;
		case R.id.radio_geren:
			mHost.setCurrentTabByTag("FOUR");
			break;
		}		
	}
}